//
//  RGInviteRecordsCell.m
//  RedGrass
//
//  Created by wuyine on 2019/2/15.
//  Copyright © 2019年 hongcaosp. All rights reserved.
//

#import "RGInviteRecordsCell.h"
#import <UIImageView+WebCache.h>

@interface RGInviteRecordsCell()
@property (nonatomic,strong) UIImageView *headIcon;
@property (nonatomic,strong) UILabel *title;
@property (nonatomic,strong) UILabel *content;
@property (nonatomic,strong) UILabel *detail;

@end

@implementation RGInviteRecordsCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:self.headIcon];
        [self.contentView addSubview:self.title];
        [self.contentView addSubview:self.content];
        [self.contentView addSubview:self.detail];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [_headIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(39, 39));
            make.centerY.mas_equalTo(0);
            make.leading.mas_equalTo(15);
        }];
        
        [_title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(16);
            make.left.mas_equalTo(self.headIcon.mas_right).mas_offset(8);
        }];
        
        [_content mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.title.mas_leading);
            make.bottom.mas_equalTo(-16);
        }];
        
        [_detail mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(-15);
            make.centerY.mas_equalTo(0);
        }];
    }
    return self;
}

-(void) setModel:(RGinvitationRecordListModel *)model{
    if(model == nil){
        return;
    }
    _model = model;
    [_headIcon sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:IMAGE_NAMED(@"个人主页_头像")];
    _title.text = SafeStr(model.nickname);
    _detail.text = [NSString stringWithFormat:@"+%@",model.invitationAmount];
    _content.text = [self makeCustomDateStringWithTime:model.createTime];
    
}

-(NSString *)makeCustomDateStringWithTime:(NSString *)time{
    NSString *resutStr = time;
    if([time length] == 13){
        NSTimeInterval time1 = [time integerValue] / 1000;
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:time1];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];//创建一个日期格式化器
        dateFormatter.dateFormat= @"YYYY.MM.dd";
        resutStr = [dateFormatter stringFromDate:date];
    }else if ([time length] == 10){
        NSTimeInterval time1 = [time integerValue];
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:time1];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];//创建一个日期格式化器
        dateFormatter.dateFormat= @"YYYY.MM.dd";
        resutStr = [dateFormatter stringFromDate:date];
    }
    return resutStr;
}

- (UIImageView *)headIcon {
    if (!_headIcon) {
        _headIcon = [[UIImageView alloc] init];
        _headIcon.layer.cornerRadius = 19.5;
        _headIcon.layer.masksToBounds = YES;
    }
    return _headIcon;
}

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.font = FONT(customFontName, 16);
        _title.textColor = UICOLOR_WITH_RGBINT(0xfffefe);
    }
    return _title;
}

- (UILabel *)content {
    if (!_content) {
        _content = [[UILabel alloc] init];
        _content.font = FONT(customFontName, 13);
        _content.textColor = UICOLOR_WITH_RGBINT(0xffffff);
    }
    return _content;
}

- (UILabel *)detail {
    if (!_detail) {
        _detail = [[UILabel alloc] init];
        _detail.font = FONT(customFontName, 18);
        _detail.textColor = UICOLOR_WITH_RGBINT(0xf73152);
    }
    return _detail;
}

@end
